<?php
class DataUserTablePlay{
    public $UserID;
    public $GameID;
    public $TableCurrentID;
    public $Status; 
    public $Time;
    public $DataID;
    static public function swap($buffer){
        $obj = new DataUserTablePlay(
                        DataUtil::readInt32(  $buffer  )  , 
                        DataUtil::readInt16(  $buffer  )  ,
                        DataUtil::readInt16(  $buffer  )  ,
                        DataUtil::readInt8(  $buffer  )  ,
                        DataUtil::readInt32(  $buffer  ) ,
                        DataUtil::readInt32(  $buffer  ) 
      );
        return $obj;
    }
    public function __construct($_userid , $_gameid , $_tablecurrentid , $_status ,$_time ,$_data_id){
       $this->UserID            =   $_userid;
       $this->TableCurrentID    =   $_tablecurrentid;
       $this->GameID            =   $_gameid;
       $this->Status            =   $_status;
       $this->Time              =   $_time;
       $this->DataID            =   $_data_id;
    }
    public function getBinsize(){
        $size = 0 ;
        $size += 4   ; 
        $size += 2   ; 
        $size += 2   ; 
        $size += 1   ; 
        $size += 4   ;
        $size += 4   ;
        return $size;
    }
    public function free(){
        $this->Status = 0;
        $this->GameID = 0;
        $this->TableCurrentID = -1;
        $this->UserID         = -1;
        $this->Time           = intval(time());
        $this->DataID         = -1;
    }
    function isTable(){
            if($this->Status == 0){
                return false;
            }
            return true;
    }
    function InPlayTable($table){       
        if(is_array($table->Players)){
            foreach ($table->Players as $player){
                if($player['id']== $this->UserID){
                        return true;
                    }
                }
        }
        return false;
    }
      function getBinary(){
        $buf = ByteBuffer::allocate(  $this->getBinsize()  )  ;
        DataUtil::writeInt32(  $buf  ,   $this->UserID  )  ;
        DataUtil::writeInt16(  $buf  ,   $this->GameID  )  ;
        DataUtil::writeInt16(  $buf  ,   $this->TableCurrentID  )  ;
        DataUtil::writeInt8(   $buf  ,   $this->Status  )  ; 
        DataUtil::writeInt32(  $buf  ,   $this->Time  )  ;
        DataUtil::writeInt32(  $buf  ,   $this->DataID  )  ;
        return  $buf ->_array();
    }
    public function SetData($_userid , $_gameid , $_tablecurrentid , $_status , $_time,$_data_id){
       $this->UserID            =   $_userid;
       $this->TableCurrentID    =   $_tablecurrentid;
       $this->GameID            =   $_gameid;
       $this->Status            =   $_status;
       $this->Time              =   $_time;
       $this->DataID            =   $_data_id;
    }
}
?>